package com.bootdo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * @author: coco
 * @time 2019/10/17 - 15:15
 */
@Slf4j
@Component
public class AsyncExceptionDemo {

    @Async
    public void simple() {
        log.info("this is a void method");
    }

    @Async
    public void inputDemo(String s) {
        log.info("this is a input method, {}", s);
        throw new IllegalArgumentException("input Errror");
    }

    @Async
    public Future hardDemo(String s) {
        log.info("this is a hard method, {} ", s);
        Future future;
        try {
            Thread.sleep(3000);
            throw new IllegalArgumentException();
        }catch (InterruptedException e){
            future = new AsyncResult("InterruptedException error");
        }catch (IllegalArgumentException e){
            future = new AsyncResult("i am throw IllegalArgumentException error");
        }
        return future;
    }
}
